<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script src="__STATIC__/plugins/jQuery/jquery-3.0.0.min.js"></script>
    <script src="__STATIC__/comm/ks-ajax-submit-new.js"></script>
    <script src="__STATIC__/admin/extend/H-ui.admin.js"></script>
    <script src="__STATIC__/admin/extend/area.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=MlsRF73Lshx3OtWWAXpG1bvvcdhIsygM"></script>
    <title>地图展示</title>
</head>
<body>
<div style="margin-left: 20px;margin-bottom: 5px;">
    <select id="s_province" name="s_province">
        <!--<option>-&#45;&#45;请选择省份-&#45;&#45;</option>-->
    </select>
    <select id="s_city" name="s_city">
        <!--<option>-&#45;&#45;请选择城市-&#45;&#45;</option>-->
    </select>
    <select id="s_county" name="s_county">
        <!--<option>-&#45;&#45;请选择地区-&#45;&#45;</option>-->
    </select>
</div>
<div id="show"></div>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">


    // 百度地图API功能
    var map = new BMap.Map("allmap");    // 创建Map实例
    //map.centerAndZoom("广西", 12);  // 初始化地图,设置中心点坐标和地图级别
    map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放


    var s = ["s_province", "s_city", "s_county"];//三个select的name
    function _init_area() {  //初始化函数
        for (var i = 0; i < s.length - 1; i++) {
            document.getElementById(s[i]).onchange = new Function("change(" + (i + 1) + ")");
            document.getElementById(s[i]).addEventListener("change",function (e) {
                map.centerAndZoom(this.value, 12);
            })
        }
        change(0);
    }
    function autoPosition() {
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                console.log(JSON.stringify(r));
                map.centerAndZoom(r.point, 12);
               // map.panTo(r.point);
                parent.$("#location").val(r.point.lng + "," + r.point.lat);
                parent.$("#longitude").val(r.point.lng);
                parent.$("#latitude").val(r.point.lat);
//                console.log('您的位置：'+r.point.lng+','+r.point.lat+'缩放比例：'+map.getZoom());
//                $("#edit_map_lng").val(r.point.lng);
//                $("#edit_map_lat").val(r.point.lat);
//                $("#edit_map_zoom").val(map.getZoom());
//                $("#edit_map").html('已定位').removeClass('color-gray');
            }
            else {
                alert('failed'+this.getStatus());
            }
        },{enableHighAccuracy: true})
    }
    autoPosition();
    _init_area();

    function showInfo(e) {
        var lng;
        var lat;
        lng = e.point.lng;
        lat = e.point.lat;
        console.log(lng + "," + lat);
        parent.$("#location").val(lng + "," + lat);
        parent.$("#longitude").val(lng);
        parent.$("#latitude").val(lat);
//        $.ajax({
//            url:'/cooperation/position_save',
//            dataType:'json',
//            data:{lat:lat,lng:lng,id:$('#id').val()},
//            success:function (res) {
//                console.log(res);
//            }
//        });
        // window.history.go(-1);
        layer_close();
    }
    map.addEventListener("click", showInfo);
</script>

